import request from '@/utils/http';
import { jsonToUrlParam, getApiUrl } from '../../urlSearchParams';
import type { MessageReceivingListDto, GetReceivedMessagesInputDto } from './type';
import type { PagedResultDto } from '../type';

// Api地址
enum API {
  DEFAULT_URL = 'api/basics/messaging/inbox'
}

// 列表接口
export const getListAsync = (input: GetReceivedMessagesInputDto) => {
  const paramenter = jsonToUrlParam(input);
  const url = getApiUrl(API.DEFAULT_URL, paramenter);
  return request.get<PagedResultDto<MessageReceivingListDto>>(url);
};

// 未读消息数量
export const getUnReadCountAsync = () => request.get<number>(`${API.DEFAULT_URL}/unReadCount`);

// 标记已读
export const markReadAsync = (id: string) =>
  request.put<boolean>(`${API.DEFAULT_URL}/markRead/${id}`);
